﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DGM.Util.Dialog.OAuth;
using DGM.Util.Helpers.MediaRatingApis.Imdb;
using DGM.Util.Helpers.MediaRatingApis.RottenTomatoes;
using DGM.Util.Helpers.Network.Lan;
using DGM.Util.Helpers.OAuth_dotnet;
using DGM.Util.Helpers.OAuth_dotnet.Clients;
using DGM.Objects.Media;
using System.Net;
using System.IO;


namespace DGM.MediaManagement
{
  public partial class DMediaManagementMain : Form
  {
    private DRTApiHelper rtApiHelper = new DRTApiHelper();

    public DMediaManagementMain()
    {
      InitializeComponent();
      rtApiHelper.DownloadCompleted += new DRTApiHelper.DownloadCompletedHandler(RTDownloadCompleted);
    }

    private void button1_Click(object sender, EventArgs e)
    {
      string movie = textBox1.Text;
      var o = DImdbApiHelper.GetMovieInfoByTitle(movie);

      lblTitle.Text = String.Format("Title: {0}", o.Title);
      lblYear.Text = String.Format("Year: {0}", o.Year);
      lblRuntime.Text = String.Format("Runtime: {0}", o.Runtime);
      lblCriticsRating.Text = String.Format("");
      lblAudienceRating.Text = String.Format("Rating: {0}", o.Rating);
      lblCriticConsensus.Text = String.Format("");

      pictureBox1.ImageLocation = o.Poster;
    }

    private void button2_Click(object sender, EventArgs e)
    {
      var o = OAuthHelper.GetOAuthClient(OAuthClient.LinkedIn, new OAuthorizeWindow());
    }

    private void button3_Click(object sender, EventArgs e)
    {
      var o = OAuthHelper.GetOAuthClient(OAuthClient.DropBox, new OAuthorizeWindow());
    }

    private void btnRottenTomato_Click(object sender, EventArgs e)
    {
      rtApiHelper.GetMovieInfo(textBox1.Text);
    }

    private void RTDownloadCompleted(object sender)
    {
      DMediaRTMovie movie = rtApiHelper.result;

      lblTitle.Text = String.Format("Title: {0}", movie.title);
      lblYear.Text = String.Format("Year: {0}", movie.year);
      lblRuntime.Text = String.Format("Runtime: {0}", movie.runtime);
      lblCriticsRating.Text = String.Format("Critics Rating: {0}", movie.ratings.critics_score);
      lblAudienceRating.Text = String.Format("Audience Rating: {0}", movie.ratings.audience_score);
      lblCriticConsensus.Text = String.Format("Critics Consensus: \n{0}", movie.critics_consensus);
      pictureBox1.Image = rtApiHelper.detailedPoster;
    }

    private void button4_Click(object sender, EventArgs e)
    {
      var list = LanComputerList.GetList();
      cbComputerList.DataSource = list;

      //NetworkBrowser a = new NetworkBrowser();
      //cbComputerList.DataSource = a.getNetworkComputers();

    }

    private void button5_Click(object sender, EventArgs e)
    {
      //      \\NICOLAAS-PC
      var list = LanSearch.ListFiles("\\NICOLAAS-PC");
      cbFiles.DataSource = list;
    }
  }
}
